package net.hn.hnms.biz.sewage.util;

import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator;

import java.io.Serializable;

/**
 * @author 智呈物联 nzw
 * @date 2022/9/24
 */
public class CustomIDGenerator extends IdentityGenerator {
    public CustomIDGenerator() {
    }

    public Serializable generate(SharedSessionContractImplementor s, Object obj) {
        try {
            Serializable id = s.getEntityPersister((String)null, obj).getClassMetadata().getIdentifier(obj, s);
            return (Serializable)(id != null ? id : IdWorker.getInstance().nextId());
        } catch (Exception var4) {
            return super.generate(s, obj);
        }
    }

}
